package cn.com.headfree.commworkflow;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.com.headfree.base.controller.ExBaseController;
import cn.com.headfree.base.controller.ResultData;
import cn.com.headfree.callback.call.IWorkFlowServerCall;


@Controller
@RequestMapping(value = "/commworkflow", produces = "application/json;charset=UTF-8")
public class CommWorkFlowController extends ExBaseController{

	private static final Logger LOG = LogManager.getLogger(CommWorkFlowController.class);

	@Autowired
	private IWorkFlowServerCall workFlowServerCall;
	/**
	 * @description 根据系统编码获取该系统下所有的工作流
	 * @author fengya
	 * @date 2020年7月1日 上午11:25:36
	 * @param sysCode
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * ResultData
	 */
	@RequestMapping(value="/findWorkFlowsBySysCode/{sysCode}",method=RequestMethod.GET)
	public ResultData findWorkFlowsBySysCode(String sysCode) {
		return workFlowServerCall.findWorkFlowsBySysCode(sysCode);
	}

	/**
	 * @description 提交工作流
	 * @author fengya
	 * @date 2020年7月1日 上午11:26:20
	 * @param workFlowId
	 * @param businessId
	 * @param workFlowApproveCondition
	 * @param currentUserId
	 * @param approveAdvise 审批意见
	 * @param domainId 业务域id
	 * @return
	 * ResultData
	 */
	@RequestMapping(value="/saveApproveRecord",method=RequestMethod.POST)
	public ResultData saveApproveRecord(String workFlowId,String businessId,String workFlowApproveCondition,String currentUserId,String approveAdvise,String domainId) {
		LOG.info("=====================成功调取human-manage的saveApproveRecord方法=========================");
		return workFlowServerCall.saveApproveRecord(workFlowId, businessId, workFlowApproveCondition, currentUserId, approveAdvise, domainId);
	}

	/**
	 * @description 审批流程
	 * @author fengya
	 * @date 2020年7月1日 下午4:57:39
	 * @param approveId
	 * @param approveAdvise
	 * @param currentUserId
	 * @param domainId 业务域id
	 * @return
	 * ResultData
	 */
	@RequestMapping(value = "/approveRecord", method = RequestMethod.POST)
	public ResultData approveRecord(String approveId,String approveAdvise,String currentUserId,String domainId,String approveCondition) {
		LOG.info("=====================成功调取human-manage的approveRecord方法=========================");
		return workFlowServerCall.approveRecord(approveId, approveAdvise, currentUserId, domainId, approveCondition);
	}

	/**
	 * @description 分页查找系统编码下所有待审批任务
	 * @author fengya
	 * @date 2020年7月1日 上午11:26:54
	 * @param sysCode
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * ResultData
	 */
	@RequestMapping(value = "/findWaitApproveWorkFlow/{sysCode}/{currentUserId}/{pageSize}/{pageNo}", method = RequestMethod.GET)
	public ResultData findWaitApproveWorkFlow(String sysCode,String currentUserId,int pageSize,int pageNo) {
		LOG.info("=====================成功调取human-manage的findWaitApproveWorkFlow方法=========================");
		return workFlowServerCall.findWaitApproveWorkFlow(sysCode, currentUserId, pageSize, pageNo);
	}

	/**
	 * @description 分页查找系统编码下所有已审批任务
	 * @author fengya
	 * @date 2020年7月1日 上午11:26:54
	 * @param sysCode
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * ResultData
	 */
	@RequestMapping(value = "/findApprovedWorkFlow/{sysCode}/{currentUserId}/{pageSize}/{pageNo}", method = RequestMethod.GET)
	public ResultData findApprovedWorkFlow(String sysCode,String currentUserId,int pageSize,int pageNo) {
		LOG.info("=====================成功调取human-manage的findApprovedWorkFlow方法=========================");
		return workFlowServerCall.findApprovedWorkFlow(sysCode, currentUserId, pageSize, pageNo);
	}

	/**
	 * @description 根据审批ID获取流程该节点审批条件数据
	 * @author fengya
	 * @date 2020年7月1日 下午3:59:56
	 * @param approveId
	 * @return
	 * ResultData
	 */
	@RequestMapping(value = "/getNextWorkFlowCondition/{approveId}", method = RequestMethod.GET)
	public ResultData getNextWorkFlowCondition(String approveId) {
		LOG.info("=====================成功调取human-manage的getNextWorkFlowCondition方法=========================");
		return workFlowServerCall.getNextWorkFlowCondition(approveId);
	}

	/**
	 * @description 根据业务ID获取该业务的审批记录
     * 	 * @author fengya
	 * @date 2020年7月1日 下午7:35:21
	 * @param businessId
	 * @return
	 * ResultData
	 */
	@RequestMapping(value = "/findApprovedRecord/{businessId}", method = RequestMethod.GET)
	public ResultData findApprovedRecord(String businessId) {
		LOG.info("=====================成功调取human-manage的findApprovedRecord方法=========================");
		return workFlowServerCall.findApprovedRecord(businessId);
	}
}
